Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

io-ts-docopt

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

io-ts-docopt

Decode docopt output with io-ts

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10K
increased by26.15%
Maintainers
1
Weekly downloads
 
Created
Source

io-ts-docopt

License NPM Package Build status Code Coverage

Decode docopt output with io-ts

Docopt is a fantastic argument-parsing tool, but suffers from a few drawbacks:

  1. The returned object has awkward keys like <name> that cannot be accessed with the dot accessor
  2. Arguments (except flags) are always parsed as strings

This project combines docopt with io-ts to overcome both inconveniences, by first parsing arguments with docopt, then decoding and then encoding the parsed value through the specified io-ts codec. This sequence provides the opportunity to remap gnarly keys into more convenient identifiers, as well as decode values from one type into another (for example, with the NumberFromString codec).

Install

npm install io-ts-docopt

Use

import { decodeDocopt, withEncode } from 'io-ts-docopt'

const docstring = `
Usage:
    foo --clean <one> <two> <many>...
`

const codec = withEncode(
    iots.type({
        '--clean': iots.boolean,
        '<one>': iots.string,
        '<two>': iots.string,
        '<many>': iots.array(iots.string)
    }),
    (a) => ({
        clean: a['--clean'],
        one: a['<one>'],
        two: a['<two>'],
        many: a['<many>']
    })
)

decodeDocopt(
    codec,
    docstring,
    {argv: `--clean red blue green purple yellow`.split(/\s+/)}
)
//=> {
//       clean: true,
//       one: "red",
//       two: "blue",
//       many: ["green", "purple", "yellow"]
//  }

Documentation

See generated documentation.

Acknowledgments

Keywords

FAQs

Package last updated on 14 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc